package day02;

import java.math.BigDecimal;

//此类适用于验证double数据类型的测试demo
public class Test05 {
    public static void main(String[] args) {
        //浮点计算double
        double b = 3.9;
        double c = 2.9;
        System.out.println(b - c);   //0.100000000000009  存在吾侪
        double e = 6.0;
        double f = 4.9;
        System.out.println(e -f);     //1.099999999999   存在误差
        double g = 6.0;
        double h = 1.9;
        System.out.println(g -h);    //结果为4.1

        //使用BigDecimal 类型可以进行精确计算
        BigDecimal x = new BigDecimal("6.0");   //定义x变量的值为6。0
        BigDecimal y = new BigDecimal("5.9");   //定义y变量的值为5.9
        BigDecimal result = x.subtract(y);            //substract()方法为减去的意思，也就是x-y
        System.out.println(result);
   }
}
